package cn.data.collection.interceptor;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import cn.data.collection.constant.CollectionParaConstant;
import cn.data.collection.constant.ThreadCommonData;
import cn.data.collection.util.CollectionHelper;
import cn.data.collection.util.HttpClientUtils;
import cn.data.collection.util.LoggerUtils;

public class ServerInitData extends HttpServlet {

	/**
	 * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void init() throws ServletException {
		super.init();
		this.satartCollection();
	}

	private void satartCollection(){
		try {
			String msg = new CollectionHelper().satartCollection();
			LoggerUtils.getInstance().error("服务启动完成！" + msg);
		} catch (Exception e) {
			LoggerUtils.getInstance().error("注意：启动出错！" + e);
		}
	}

	@Override
	public void destroy() {
		super.destroy();
		CollectionParaConstant.autoRunFlag = Boolean.FALSE;
		for(HttpClientUtils objHttpClientUtils : ThreadCommonData.LST_HTTPCLIENTUTILS){
			objHttpClientUtils.releaseConnection();
		}
		System.out.println("关闭线程完毕..............................");
	}

}
